import requests

headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Cache-Control": "max-age=0",
    "Connection": "keep-alive",
    "Sec-Fetch-Dest": "document",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-Site": "none",
    "Sec-Fetch-User": "?1",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
    "sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"macOS\"",
    "Referer": "https://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=3d&issueCount=&issueStart=&issueEnd=&dayStart=&dayEnd=&pageNo=1&pageSize=100&week=&systemType=PC"
}
cookies = {
    "21_vq": "5",
    "HMF_CI": "4956d575ea36ee688a78e8aa60715c5ecd85975f007c03cbb76c1e48dc9c5030919c1b5c0433d0d29d9001fd6b51164e88e480270261905c5310cd409751c51fd2"
}
url = "https://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice"

# url = "https://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=3d&issueCount=&issueStart" \
#       "=&issueEnd=&dayStart=&dayEnd=&pageNo={}&pageSize=100&week=&systemType=PC "
saveList = []

for i in range(1, 30):
    params = {
        "name": "3d",
        "issueCount": "",
        "issueStart": "",
        "issueEnd": "",
        "dayStart": "",
        "dayEnd": "",
        "pageNo": str(i),
        "pageSize": "100",
        "week": "",
        "systemType": "PC"
    }
    response = requests.get(url, headers=headers, cookies=cookies, params=params)
    resultList = response.json()['result']
    for item in resultList:
        saveList.append("{}|{}|{}".format(item['code'], item['date'], item['red']))

fh = open("fc3d1.txt", 'a')

for item in saveList:
    fh.write(item + "\r\n")
fh.close()
